1 /** 2 * This file is part of libphidget21 3 * 4 * Copyright 2006-2015 Phidgets Inc <patrick@phidgets.com> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 3 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, see 18 * <http://www.gnu.org/licenses/> 19 */ 20 module phidget21.phiddict; 21 22 extern(C) __gshared { 23 enum CPhidgetDictionary_keyChangeReason { 24 PHIDGET_DICTIONARY_VALUE_CHANGED = 1, /**< The value of an existing key/value pair changed. */ 25 PHIDGET_DICTIONARY_ENTRY_ADDED, /**< A new key/value pair was added. */ 26 PHIDGET_DICTIONARY_ENTRY_REMOVING, /**< A key is being removed. */ 27 PHIDGET_DICTIONARY_CURRENT_VALUE /**< Initial state received once a handler was added. */ 28 } 29 30 /** 31 * A Phidget Dictionary handle. 32 */ 33 struct _CPhidgetDictionary; 34 alias CPhidgetDictionaryHandle = _CPhidgetDictionary*; 35 36 /** 37 * A Dictionary key listener handle. 38 */ 39 struct _CPhidgetDictionaryListener; 40 alias CPhidgetDictionaryListenerHandle = _CPhidgetDictionaryListener*; 41 42 /** 43 * Creates a Phidget Dictionary handle. 44 * 45 * Params: 46 * dict = A pointer to an unallocated phidget dictionary handle. 47 */ 48 int function(CPhidgetDictionaryHandle* dict) CPhidgetDictionary_create; 49 50 /** 51 * Closes the connection to a Phidget Dictionary. 52 * 53 * Params: 54 * dict = An opened phidget dictionary handle. 55 */ 56 int function(CPhidgetDictionaryHandle dict) CPhidgetDictionary_close; 57 58 /** 59 * Frees a Phidget Dictionary handle. 60 * 61 * Params: 62 * A closed Dictionary handle. 63 */ 64 int function(CPhidgetDictionaryHandle dict) CPhidgetDictionary_delete; 65 66 alias CPhidgetDictionary_set_OnError_Handler_Func = extern(C) int function(CPhidgetDictionaryHandle, void* userPtr, int errorCode, const char* errorString); 67 /** 68 * Sets the error handler callback function. This is called when an asyncrhonous error occurs. 69 * 70 * Params: 71 * dict = A phidget dictionary handle. 72 * fptr = Callback function pointer. 73 * userPtr = A pointer for use by the user - this value is passed back into the callback function. 74 */ 75 int function(CPhidgetDictionaryHandle dict, CPhidgetDictionary_set_OnError_Handler_Func fptr, void* userPtr) CPhidgetDictionary_set_OnError_Handler; 76 77 /** 78 * Adds a key/value pair to the dictionary. Or, changes an existing key's value. 79 * 80 * Params: 81 * dict = A connected dictionary handle. 82 * key = The key value. 83 * value = The value value. 84 * persistent = Whether the key stays in the dictionary after disconnection. 85 */ 86 int function(CPhidgetDictionaryHandle dict, const char* key, const char* value, int persistent) CPhidgetDictionary_addKey; 87 88 /** 89 * Removes a set of keys from the dictionary. 90 * 91 * Params: 92 * dict = A connected dictionary handle. 93 * pattern = A regular expression representing the set of keys to remove. 94 */ 95 int function(CPhidgetDictionaryHandle dict, const char* pattern) CPhidgetDictionary_removeKey; 96 97 98 /** 99 * Callback function for KeyChange events. 100 * 101 * Params: 102 * dict = Dictionary from which this event originated. 103 * userPtr = User defined data. 104 * value = Value value. 105 * reason = Reason for KeyChange event. 106 */ 107 alias CPhidgetDictionary_OnKeyChange_Function = extern(C) int function(CPhidgetDictionaryHandle dict, void* userPtr, const char* key, const char* value, CPhidgetDictionary_keyChangeReason reason); 108 109 /** 110 * Adds a key listener to an opened dictionary. Note that this should only be called afrter the connection to the 111 * dictionary has been made - unlike all other events. 112 * 113 * Params: 114 * dict = A connected dictionary handle. 115 * dictlistener = A pointer to an unallocated dictionary key listener handle. 116 * pattern = A regular expression representing the set of keys to monitor. 117 * fptr = Callback function pointer. 118 * userPtr = A pointer for use by the user - this value is passed back into the callback function. 119 */ 120 int function(CPhidgetDictionaryHandle dict, CPhidgetDictionaryListenerHandle* dictlistener, const char* pattern, CPhidgetDictionary_OnKeyChange_Function fptr, void* userPtr) CPhidgetDictionary_set_OnKeyChange_Handler; 121 122 /** 123 * Removes a key listener. 124 * 125 * Params: 126 * dictlistener = The dictionary key listener created by CPhidgetDictionary_set_OnKeyChange_Handler 127 */ 128 int function(CPhidgetDictionaryListenerHandle dictlistener) CPhidgetDictionary_remove_OnKeyChange_Handler; 129 130 /** 131 * Gets a key value. If more then one key matches, only the first value is returned. 132 * 133 * Params: 134 * dict = A phidget dictionary handle. 135 * key = A key value to look up. 136 * value = A user array for the value to be stored in. Set to null if the key does not exist. 137 * valuelen = Length of the value array. 138 */ 139 int function(CPhidgetDictionaryHandle dict, const char* key, char* value, int valuelen) CPhidgetDictionary_getKey; 140 141 alias CPhidgetDictionary_set_OnServerConnect_Handler_Func = extern(C) int function(CPhidgetDictionaryHandle dict, void* userPtr); 142 /** 143 * Sets a server connect handler callback function. This is called when a connection to the server has been made. 144 * 145 * Params: 146 * dict = A phidget dictionary handle. 147 * fptr = Callback function pointer. 148 * userPtr = A pointer for use by the user - this value is passed back into the callback function. 149 */ 150 int function(CPhidgetDictionaryHandle dict, CPhidgetDictionary_set_OnServerConnect_Handler_Func fptr, void* userPtr) CPhidgetDictionary_set_OnServerConnect_Handler; 151 152 alias CPhidgetDictionary_set_OnServerDisconnect_Handler_Func = extern(C) int function(CPhidgetDictionaryHandle dict, void* userPtr); 153 /** 154 * Sets a server disconnect handler callback function. This is called when a connection to the server has been lost. 155 * 156 * Params: 157 * dict = A phidget dictionary handle. 158 * fptr = Callback function pointer. 159 * userPtr = A pointer for use by the user - this value is passed back into the callback function. 160 */ 161 int function(CPhidgetDictionaryHandle dict, CPhidgetDictionary_set_OnServerDisconnect_Handler_Func fptr, void* userPtr) CPhidgetDictionary_set_OnServerDisconnect_Handler; 162 163 /** 164 * Gets the server ID. 165 * 166 * Params: 167 * dict = A connected dictionary handle. 168 * serverID = A pointer which will be set to a char array containing the server ID string. 169 */ 170 int function(CPhidgetDictionaryHandle dict, const char** serverID) CPhidgetDictionary_getServerID; 171 172 /** 173 * Gets the address and port. 174 * 175 * Params: 176 * dict = A connected dictionary handle. 177 * address = A pointer which will be set to a char array containing the address string. 178 * port = An int pointer for returning the port number. 179 */ 180 int function(CPhidgetDictionaryHandle dict, const char** address, int* port) CPhidgetDictionary_getServerAddress; 181 182 /** 183 * Gets the connected to server status. 184 * 185 * Params: 186 * dict = An opened dictionary handle. 187 * serverStatus = An int pointer for returning the server status. Possible codes are PHIDGET_ATTACHED and PHIDGET_NOTATTACHED. 188 */ 189 int function(CPhidgetDictionaryHandle dict, int* serverStatus) CPhidgetDictionary_getServerStatus; 190 191 /** 192 * Opens a Phidget dictionary by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server. 193 * 194 * Params: 195 * dict = A phidget dictionary handle. 196 * serverID = ServerID. Specify NULL to open any. 197 * password = Password. Can be NULL if the server is running unsecured. 198 */ 199 int function(CPhidgetDictionaryHandle dict, const char* serverID, const char* password) CPhidgetDictionary_openRemote; 200 201 /** 202 * Opens a Phidget dictionary by address and port. 203 * 204 * Params: 205 * dict = A phidget dictionary handle. 206 * address = Address. This can be a hostname or IP address. 207 * port = Port number. Default is 5001. 208 * password = Password. Can be NULL if the server is running unsecured. 209 */ 210 int function(CPhidgetDictionaryHandle dict, const char* address, int port, const char* password) CPhidgetDictionary_openRemoteIP; 211 }